﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Xms.Abp.BackgroundJob;

namespace Xms.Abp.Messaging.Emailing;

public class TemplateEmailSender : EmailSenderBase, IEmailSender, ITransientDependency
{
    protected IServiceProvider Services { get; }
    public TemplateEmailSender(
        IServiceProvider services,
        IBackgroundJobManager backgroundJobManager,
        ICurrentTenant currentTenant)
        : base(backgroundJobManager, currentTenant)
    {
        Services = services;
    }
    protected override async Task SendEmailAsync(EmailMessage emailMessage, CancellationToken stoppingToken = default)
    {
        var client = Services.GetRequiredService<ITemplateEmailSenderProvider>();
        await client.SendEmailAsync(emailMessage, stoppingToken);
    }
}
